package net.ifilm.common;

import net.ifilm.db.DBExecutor;

import java.util.HashMap;
import java.util.Map;

/**
 * CreateBy: <a href="wangjunneil@gmail.com">Calvin</a>
 * CreateTime: 2013-11-22 16:01
 */
public class SpiderCache {

    private static SpiderCache instance = null;

    private boolean initial = false;

    private DBExecutor dbExecutor = new DBExecutor();

    private Map<String, Object> filmNameMap = new HashMap<String, Object>();

    private Map<String, Object> reverseFilmNameMap = new HashMap<String, Object>();

    private Map<String, Object> filmActorMap = new HashMap<String, Object>();

    private SpiderCache() { }

    public static SpiderCache getInstance() {
        if (instance == null) {
            instance = new SpiderCache();
        }
        return instance;
    }

    public void initialCache() throws Exception {
        if (initial) return;

        this.filmNameMap = dbExecutor.findFilmNamelist();
        this.reverseFilmNameMap = dbExecutor.findReverseFilmNameMap();
        this.filmActorMap = dbExecutor.findFilmActorList();

        initial = true;
    }

    public Map<String, Object> getFilmNameMap() {
        return filmNameMap;
    }

    public Map<String, Object> getFilmActorMap() {
        return filmActorMap;
    }

    public Map<String, Object> getReverseFilmNameMap() {
        return reverseFilmNameMap;
    }

    public Object getFilmNameMapValue(String key) {
        return this.filmNameMap.get(key);
    }

    public Object getReverseFilmNameMapValue(String key) {
        return this.reverseFilmNameMap.get(key);
    }

    public Object getFilmActorMapValue(String key) {
        return this.filmActorMap.get(key);
    }


}
